from PyPDF2 import PdfFileMerger
import argparse


def parse_args():
    """Get user command line parameters"""
    parser = argparse.ArgumentParser(description="Available Options")
    parser.add_argument('-i', '--input_files', dest='input_files', nargs='*',
                        type=str, required=True, help="Enter the path of the files to process")
    parser.add_argument('-o', '--output_file', dest='output_file',
                        required=True, type=str, help="Enter a valid path of merged file")
    # To Parse The Command Line Arguments
    parsed_args = parser.parse_args()
    args_dict = vars(parsed_args)
    # To Display The Command Line Arguments
    print("## Command Arguments #################################################")
    print("\n".join("{}: {}".format(i, j) for i, j in args_dict.items()))
    print("######################################################################")
    return args_dict


def merge(input_paths: list, output_path: str):
    merger = PdfFileMerger()

    for pdf in input_paths:
        merger.append(pdf)

    merger.write(output_path)
    merger.close()


if __name__ == '__main__':
    args = parse_args()
    merge(input_paths=args['input_files'], output_path=args['output_file'])
